home *** CD-ROM | disk | FTP | other *** search
- Path: ix.netcom.com!als-il4-33
- From: stefmit@ix.netcom.com
- Newsgroups: comp.lang.c++
- Subject: Re: [Q] Expression tree evaluation
- Date: 14 Apr 1996 16:22:36 GMT
- Organization: Netcom
- Message-ID: <4kr8oc$7bj@dfw-ixnews8.ix.netcom.com>
- References: <4kp8ja$s6p@cloner2.ix.netcom.com>
- NNTP-Posting-Host: als-il4-33.ix.netcom.com
- X-NETCOM-Date: Sun Apr 14 11:22:36 AM CDT 1996
- X-Newsreader: News Xpress Version 1.0 Beta #4
-
- In article <4kp8ja$s6p@cloner2.ix.netcom.com>, stefmit@ix.netcom.com wrote:
- >Could anybody tell me what's wrong with this (I am surely missing something):
- >
- >float ExprTree :: evaluate () const
- >{ if (root != 0)
- > evaluateSub (root); }
- >
- >float ExprTree :: evaluateSub (ExprTreeNode *p) const
- >{ float result, l, r;
- > if (isdigit (p -> element))
- > result = ((p -> element) - '0');
- > else { l = evaluateSub (p -> left);
- > r = evaluateSub (p -> right); }
- > switch (p -> element) {
- > case '+' : result = l+r; break;
- > case '-' : result = l-r; break;
- > case '*' : result = l*r; break;
- > case '/' : result = l/r; break;
- > default : break;}
- > return (result); }
- >
- >I am obviously trying to evaluate an expression, I "watched" l, r and result
- >and they show correct values (while stepping through the program), but the
- >program crashes with "stack underflow". Could anybody help, please? Thanks.
-
-
- Sorry, it's me again - I missed the return in the main evaluate. Stupid, isn't
- it? I looked so hard at the Sub one, that I missed the main one. Sorry again.
-